package com.fs.m.server.util;

import java.util.Map;

/**
 * Map的工具类
 *
 * User: zhuguoyin
 * Date: 13-10-7
 * Time: 下午1:38
 * To change this template use File | Settings | File Templates.
 */
public class MapUtil {

    public static String getString(Map map, String key) {
        Object value = map.get(key);
        if (value instanceof String) {
            return (String) value;
        }
        return null;
    }

    public static Map getMap(Map map, String key) {
        Object value = map.get(key);
        if (value instanceof Map) {
            return (Map) value;
        }
        return null;
    }

    public static int getInt(Map map, String key) {
        Object value = map.get(key);
        if (value instanceof Integer) {
            return (Integer) value;
        }

        if (value instanceof Number) {
            return ((Number) value).intValue();
        }

        if (value instanceof String) {
            return Integer.parseInt((String) value);
        }
        throw new IllegalArgumentException(key + "is not integer");
    }
}
